<template>
  <div class="maintenance-analysis">
    <el-form inline>
      <el-form-item label="日期区间">
        <el-date-picker
            v-model="dateRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="fetchData"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="fetchData">查询</el-button>
      </el-form-item>
    </el-form>
    <div class="chart">
      <!-- 这里可以使用一个图表库，如Chart.js或ECharts来渲染图表 -->
      <canvas id="myChart"></canvas>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { ElForm, ElFormItem, ElDatePicker, ElButton } from 'element-plus';
import Chart from 'chart.js/auto';

const dateRange = ref([]);
const maintenanceData = ref([]);

const fetchData = () => {
  // 调用API获取数据
  console.log('查询条件:', { dateRange: dateRange.value });
  // 模拟数据
  maintenanceData.value = [
    { name: '张三', date: '2023-05-01', status: '已完成' },
    { name: '李四', date: '2023-05-02', status: '进行中' },
  ];
};

const drawChart = () => {
  const ctx = document.getElementById('myChart').getContext('2d');
  const myChart = new Chart(ctx, {
    type: 'line',
    data: {
      labels: ['1', '2', '3', '4', '5'],
      datasets: [
        {
          label: '报修数量',
          data: [12, 19, 3, 5, 2],
          backgroundColor: 'rgba(255, 99, 132, 0.2)',
          borderColor: 'rgba(255, 99, 132, 1)',
          borderWidth: 1,
        },
        {
          label: '维修数量',
          data: [18, 15, 7, 12, 5],
          backgroundColor: 'rgba(54, 162, 235, 0.2)',
          borderColor: 'rgba(54, 162, 235, 1)',
          borderWidth: 1,
        },
      ],
    },
  });
};

onMounted(() => {
  drawChart();
});
</script>

<style scoped>
.maintenance-analysis {
  padding: 20px;
}
.chart {
  max-width: 600px;
  margin: 20px auto;
}
</style>